package com.ai.analysis.json;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class JokeRead implements IJsonRead {

	@Override
	public String readQuery(JSONObject json) {
		StringBuffer bf = new StringBuffer();
		JSONObject data = json.getJSONObject("data");
		JSONArray arr1 = data.getJSONArray("result");
		for (int i = 0; i < arr1.size(); i++) {
			JSONObject row = arr1.getJSONObject(i);
			/*
			"airQuality": "优",
            "sourceName": "中国天气网",
            "date": "2017-08-10",
            "lastUpdateTime": "2017-08-10 08:00:00",
            "dateLong": 1502294400,
            "pm25": "28",
            "city": "成都",
            "humidity": "95%",
            "windLevel": 0,
            "weather": "阴转阵雨",
            "tempRange": "22℃~33℃",
            "wind": "无持续风向微风"
			*/
			String city = row.getString("city");
			String date = row.getString("date");
			String weather = row.getString("weather");
			String tempRange = row.getString("tempRange");
			String wind = row.getString("wind");
			bf.append(date).append(" ");
			bf.append(city).append(" ");
			bf.append(weather).append(" ");
			bf.append(tempRange).append(" ");
			bf.append(wind).append(" ");
		}
		return bf.toString();
	}

	@Override
	public String readAnswer(JSONObject json) {
		// TODO Auto-generated method stub
		return null;
	}

	/*
{
    "moreResults": [
        {
            "rc": 0,
            "answer": {
                "type": "T",
                "text": "天气是指某一个地方距离地表较近的大气层在短时间内的具体状态。而天气现象则是指发生在大气中发生的各种自然现象，即某瞬时内大气中各种气象要素（如气温、气压、湿度、风、云、雾、雨、雪、霜、雷、雹等）空间分布的综合表现。天气过程就是一定地区的天气现象随时间的变化过程。"
            },
            "service": "baike",
            "text": "天气",
            "operation": "ANSWER"
        }
    ],
    "webPage": {
        "header": "",
        "url": "http://kcgz.openspeech.cn/service/iss?wuuid=c3ef34853562e8d95b6df0131423503b&ver=2.0&method=webPage&uuid=901e000b244fc231638a0cf74ffef1ebquery"
    },
    "semantic": {
        "slots": {
            "location": {
                "type": "LOC_POI",
                "city": "CURRENT_CITY",
                "poi": "CURRENT_POI"
            },
            "datetime": {
                "date": "CURRENT_DAY",
                "type": "DT_BASIC"
            }
        }
    },
    "rc": 0,
    "operation": "QUERY",
    "service": "weather",
    "data": {
        "result": [
            {
                "airQuality": "优",
                "sourceName": "中国天气网",
                "date": "2017-08-10",
                "lastUpdateTime": "2017-08-10 08:00:00",
                "dateLong": 1502294400,
                "pm25": "28",
                "city": "成都",
                "humidity": "95%",
                "windLevel": 0,
                "weather": "阴转阵雨",
                "tempRange": "22℃~33℃",
                "wind": "无持续风向微风"
            },
            {
                "dateLong": 1502380800,
                "sourceName": "中国天气网",
                "date": "2017-08-11",
                "lastUpdateTime": "2017-08-10 08:00:00",
                "city": "成都",
                "windLevel": 0,
                "weather": "小雨转晴",
                "tempRange": "21℃~28℃",
                "wind": "无持续风向微风"
            },
            {
                "dateLong": 1502467200,
                "sourceName": "中国天气网",
                "date": "2017-08-12",
                "lastUpdateTime": "2017-08-10 08:00:00",
                "city": "成都",
                "windLevel": 0,
                "weather": "多云转晴",
                "tempRange": "24℃~32℃",
                "wind": "无持续风向微风"
            },
            {
                "dateLong": 1502553600,
                "sourceName": "中国天气网",
                "date": "2017-08-13",
                "lastUpdateTime": "2017-08-10 08:00:00",
                "city": "成都",
                "windLevel": 0,
                "weather": "多云",
                "tempRange": "24℃~33℃",
                "wind": "无持续风向微风"
            },
            {
                "dateLong": 1502640000,
                "sourceName": "中国天气网",
                "date": "2017-08-14",
                "lastUpdateTime": "2017-08-10 08:00:00",
                "city": "成都",
                "windLevel": 0,
                "weather": "多云",
                "tempRange": "24℃~33℃",
                "wind": "无持续风向微风"
            },
            {
                "dateLong": 1502726400,
                "sourceName": "中国天气网",
                "date": "2017-08-15",
                "lastUpdateTime": "2017-08-10 08:00:00",
                "city": "成都",
                "windLevel": 0,
                "weather": "多云转阵雨",
                "tempRange": "24℃~33℃",
                "wind": "无持续风向微风"
            },
            {
                "dateLong": 1502812800,
                "sourceName": "中国天气网",
                "date": "2017-08-16",
                "lastUpdateTime": "2017-08-10 08:00:00",
                "city": "成都",
                "windLevel": 0,
                "weather": "小雨转中雨",
                "tempRange": "25℃~31℃",
                "wind": "无持续风向微风"
            }
        ]
    },
    "text": "天气"
}
	 */
}
